package day1104.demo03;

import java.util.ArrayList;
import java.util.Collections;
import java.util.function.Consumer;
import java.util.function.Predicate;

/**
 * @program: qy158
 * @description:
 * @author: 闫克起2
 * @create: 2022-11-04 10:29
 **/
public class Test {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list, "张无忌", "周芷若", "赵敏", "张强", "张三丰");


       // Consumer<String> consumer=item-> System.out.println(item);
        list.stream()
                .filter(item->item.startsWith("张"))
                .filter(item->item.length()==3)
                .forEach(item-> System.out.println(item));

    }

    public static void fun(){
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list, "张无忌", "周芷若", "赵敏", "张强", "张三丰");

        //1.获取所有姓张。
        ArrayList<String> newList = new ArrayList<>();
        for(String n:list){
            if(n.startsWith("张")){
                newList.add(n);
            }
        }

        //2. 名字中含有三个的字
        ArrayList<String> newList2 = new ArrayList<>();
        for(String n:newList){
            if(n.length()==3){
                newList2.add(n);
            }
        }

        //3.打印
        for (String s:newList2){
            System.out.println(s);
        }

    }
}
